package org.swim.core.entities;

// Generated Dec 7, 2012 12:57:21 AM by Hibernate Tools 3.4.0.CR1

import static javax.persistence.GenerationType.IDENTITY;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.swim.remote.entities.IFriendship;
import org.swim.remote.entities.INotification;


/**
 * Friendship generated by hbm2java
 */
@Entity
@Table(name = "Friendship", catalog = "jboss", uniqueConstraints = @UniqueConstraint(columnNames = {
		"senderId", "receiverId" }))
public class Friendship extends SwimEntity implements java.io.Serializable, IFriendship, INotification {

	private static final long serialVersionUID = 1L;
	
	private Integer id;
	private User userBySenderId;
	private User userByReceiverId;
	private Status status = Status.REQUESTED;
	private NotificationStatus notificationStatus = NotificationStatus.UNREAD;
	private Date timestamp = new Date(System.currentTimeMillis());

	public Friendship() {
	}

	public Friendship(User userBySenderId, User userByReceiverId, Status status) {
		this.userBySenderId = userBySenderId;
		this.userByReceiverId = userByReceiverId;
		this.status = status;
	}

	/* (non-Javadoc)
	 * @see org.swim.entities.IFriendship#getId()
	 */
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	@Enumerated(EnumType.STRING)
	@Column(name = "notificationStatus", nullable = false, columnDefinition = "ENUM('UNREAD', 'READ', 'HIDDEN'")//, length = 2)
	public NotificationStatus getNotificationStatus() {
		return notificationStatus;
	}

	public void setNotificationStatus(NotificationStatus notificationStatus) {
		this.notificationStatus = notificationStatus;
	}

	// @Version
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.swim.entities.IMessage#getTimestamp()
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "ts", nullable = false, length = 19)
	public Date getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}

	/* (non-Javadoc)
	 * @see org.swim.entities.IFriendship#getUserBySenderId()
	 */
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "senderId", nullable = false)
	public User getUserBySenderId() {
		return this.userBySenderId;
	}

	public void setUserBySenderId(User userBySenderId) {
		this.userBySenderId = userBySenderId;
	}

	/* (non-Javadoc)
	 * @see org.swim.entities.IFriendship#getUserByReceiverId()
	 */
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "receiverId", nullable = false)
	public User getUserByReceiverId() {
		return this.userByReceiverId;
	}

	public void setUserByReceiverId(User userByReceiverId) {
		this.userByReceiverId = userByReceiverId;
	}

	/* (non-Javadoc)
	 * @see org.swim.entities.IFriendship#getStatus()
	 */
	@Enumerated(EnumType.STRING)
	@Column(name = "status", nullable = false, length = 10, columnDefinition = "ENUM('REQUESTED', 'CONFIRMED', 'REJECTED')")
	public Status getStatus() {
		return this.status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	@Transient
	public String getNotificationType() {
		return Friendship.class.getSimpleName();
	}

}
